function listToTree(list){
    const map = new Map(list.map(item => [item.id, item.dataValues ]));
    const roots = [];
    for (const item of map.values()) {
        const parent = map.get(item.parentId);
        if(parent){
            if(parent.childrenList){
                parent.childrenList.push(item)
            } else {
                parent.childrenList = [item]
            }
        } else{
            roots.push(item);
        }
        // parent ? parent.childrenList.push(item) : roots.push(item);
    }
    return roots;
}

module.exports.listToTree = listToTree
